﻿using MaterialSkin;
using MaterialSkin.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TomatoClock.Services;

namespace TomatoClock.Views
{
    public partial class AddProcessForm : MaterialForm
    {
        public ProcessManager processManager;
        public string ProcessName;
        private readonly MaterialSkinManager materialSkinManager;

        private float x; //定义当前窗体的宽度
        private float y; //定义当前窗体的高度

        public AddProcessForm(ProcessManager processManager)
        {
            InitializeComponent();
            this.processManager = processManager;
            updatematerialListBox1();

        }
        //传回入口
        private void materialButton1_Click(object sender, EventArgs e)
        {
            ProcessName = materialTextBox1.Text.Trim();
            DialogResult = DialogResult.OK;
            Close();
        }

        private void materialButton2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private void updatematerialListBox1()
        {
            materialListBox1.Items.Clear();
            List<string> processs = processManager.GetCurrentProcess();
            foreach (string process in processs)
            {
                MaterialSkin.MaterialListBoxItem item = new MaterialSkin.MaterialListBoxItem(process);
                materialListBox1.Items.Add(item);
            }
        }

        private void materialButton3_Click(object sender, EventArgs e)
        {
            updatematerialListBox1();
        }
     
        private void materialListBox1_SelectedIndexChanged(object sender, MaterialListBoxItem selectedItem)
        {
            // 检查是否选中了项
            if (materialListBox1.SelectedItem != null)
            {
                // 获取选中的项并将其文本设置到 materialTextBox1 上
                MaterialSkin.MaterialListBoxItem SelectedItem = materialListBox1.SelectedItem as MaterialSkin.MaterialListBoxItem;
                if (SelectedItem != null)
                {
                    materialTextBox1.Text = SelectedItem.Text;
                }
            }
        }
    }
}

